package com.sigerap.comprobante.service;

import javax.persistence.EntityManager;
import javax.persistence.EntityTransaction;

import com.sigerap.common.util.Utilitario;
import com.sigerap.comprobante.model.Comprobante;
import com.sigerap.comprobante.model.dao.ComprobanteDAO;
import com.sigerap.comprobante.model.dao.jpa.JPAComprobanteDAO;

/**
 * 
 * @author Spirit-20121
 *
 */
public class ComprobanteService {
	private EntityManager em;
	private ComprobanteDAO comprobanteDAO;
	
	public ComprobanteService(){
		em=Utilitario.getInstance().getEntityManager();
		comprobanteDAO=new JPAComprobanteDAO(em);
	}
	
	public Comprobante registrarProveedor(Comprobante c) {
		// TODO Auto-generated method stub
		Comprobante comprobante=null;
		EntityTransaction tx=em.getTransaction();
		try{
			tx.begin();
			comprobante=comprobanteDAO.insert(c);
			tx.commit();
		}catch(Exception ex){
			tx.rollback();
			ex.printStackTrace();
			throw new RuntimeException("No se pudo eliminar");
		}
		return comprobante;
	}

}
